package site.luojie.common.vo;


import lombok.Data;

import java.io.Serializable;

/**
 * 响应数据类
 *
 * @author jie.luo
 * @since 2020-06-01
 */
@Data
public class ResultVo<T> implements Serializable {

    private ResultVo() {
    }

    /**
     * 响应码
     */
    private String code;
    /**
     * 响应提示信息
     */
    private String message;
    /**
     * 响应数据
     */
    private T data;

    /**
     * 请求成功
     *
     * @return ResultVo
     */
    public static <T> ResultVo<T> ok() {
        ResultVo<T> result = new ResultVo<T>();
        result.setCode("200");
        result.setMessage("请求成功");
        return result;
    }

    /**
     * 请求成功
     *
     * @param data Object
     * @return ResultVo
     */
    public static <T> ResultVo<T> ok(T data) {
        ResultVo<T> result = new ResultVo<T>();
        result.setCode("200");
        result.setMessage("请求成功");
        result.setData(data);
        return result;
    }

    /**
     * 自定义响应数据
     *
     * @param code    响应码
     * @param message 响应提示信息
     * @return ResultVo
     */
    public static <T> ResultVo<T> customData(String code, String message) {
        ResultVo<T> result = new ResultVo<T>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    /**
     * sentinel
     *
     * @return ResultVo
     */
    public static <T> ResultVo<T> sentinel() {
        ResultVo<T> result = new ResultVo<T>();
        result.setCode("429");
        result.setMessage("请稍后再试");
        return result;
    }
}

